package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoomDto;
import com.zzyl.service.RoomService;
import com.zzyl.vo.RoomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/room")
@Api(tags = "房间管理")
public class RoomController extends BaseController {
    @Autowired
    private RoomService roomService;
    @PostMapping("/add")
    @ApiOperation("添加房间")
    public ResponseResult add( @ApiParam("房间信息") @RequestBody RoomDto roomDto){
        roomService.add(roomDto);
        return success();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除房间")
    public ResponseResult delete(@ApiParam("删除房间的id")@PathVariable Integer id){
        roomService.delete(id);
        return success();
    }

    @GetMapping("/get/{id}")
    public ResponseResult<RoomVo> getRoomById( @ApiParam("根据id查找房间")@PathVariable Integer id){
        RoomVo roomVo=roomService.getRoomById(id);
        return success(roomVo);
    }

    @GetMapping("/getRoomsByFloorId/{floorId}")
    @ApiOperation("获取所有房间（入住配置）")
    public ResponseResult<List<RoomVo>> getRoomsByFloorId(@PathVariable Long floorId) {

        return success(roomService.getRoomsByFloorId(floorId));
    }


    @GetMapping("/getRoomsCheckedByFloorId/{floorId}")
    @ApiOperation("获取所有房间（床位房型）")
    public ResponseResult<List<RoomVo>> getRoomsCheckedByFloorId(@PathVariable Long floorId) {
        return success(roomService.getRoomsCheckedByFloorId(floorId));
    }

    @GetMapping("/getRoomsWithNurByFloorId/{floorId}")
    @ApiOperation("获取所有房间（负责老人）")
    public ResponseResult<List<RoomVo>> getRoomsWithNurByFloorId(@PathVariable Long floorId) {
        return success(roomService.getRoomsWithNurByFloorId(floorId));
    }

    /**
     * 修改房间信息
     * @param roomDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改房间信息")
    public ResponseResult update(@ApiParam("房间信息") @RequestBody RoomDto roomDto){
        roomService.update(roomDto);
        return success();
    }
    @GetMapping("/getAllVo")
    public ResponseResult<List<RoomVo>> getAllRooms(){
       List <RoomVo> roomVos = roomService.getAllRooms();
     return success(roomVos);
    }

}
